//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//

package com.qdsg.modulesihealsdk.detectStrategy.strategy.gluStrategy;

import android.content.Context;
import android.text.TextUtils;
import android.util.Log;

import com.ghalife.gha_ble.Bean.Drug;
import com.ghalife.gha_ble.Bean.InitTimeBean;
import com.ghalife.gha_ble.Bean.UserInfo;
import com.ghalife.gha_ble.Bean.W_GluResult;
import com.ghalife.gha_ble.W_GlumeterEvent;
import com.ghalife.gha_ble.W_GlumeterEventType;
import com.ghalife.gha_ble.W_GlumeterListener;
import com.ghalife.gha_ble.net.NetUtil;
import com.ghalife.gha_ble.net.update.CheckResponseResult;
import com.ghalife.gha_ble.net.update.NetworkUtil;
import com.ghalife.gha_ble.net.update.RegisterResponseResult;
import com.ghalife.gha_ble.net.update.ResponseResultUpdate;
import com.ghalife.gha_ble.net.userManager.Metric;
import com.ghalife.gha_ble.net.userManager.ResponseResult;
import com.ghalife.gha_ble.net.userManager.UpdateUserInfoParam;
import com.ghalife.gha_ble.net.userManager.UserInfoParam;
import com.ghalife.gha_ble.net.userManager.UserTestResultParam;
import com.ghalife.gha_ble.util.BuildConfigUtil;
import com.ghalife.gha_ble.util.MealUtil;
import com.ghalife.gha_ble.util.NumberUtil;
import com.google.gson.Gson;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import cn.com.heaton.blelibrary.packaging.bean.BleRssiDevice;
import cn.com.heaton.blelibrary.packaging.bean.CMD01Bean;
import cn.com.heaton.blelibrary.packaging.bean.GluReault;
import cn.com.heaton.blelibrary.packaging.bean.OriginalDataBean;
import cn.com.heaton.blelibrary.packaging.ctrl.AbstractWorker;
import cn.com.heaton.blelibrary.packaging.ctrl.GlumeterEvent;
import cn.com.heaton.blelibrary.packaging.ctrl.GlumeterEventType;
import cn.com.heaton.blelibrary.packaging.ctrl.GlumeterListener;
import cn.com.heaton.blelibrary.packaging.ctrl.GlumeterWorker;
import cn.com.heaton.blelibrary.packaging.ctrl.SelfTestWorker;
import cn.com.heaton.blelibrary.packaging.update.Total_BluetoothUpdateWorker;
import cn.com.heaton.blelibrary.packaging.update.bluetooth.ProgressBean;
import okhttp3.ResponseBody;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

public class W_S_GlumeterWorker {
    protected static final String TAG = "W_S_GlumeterWorker";
    private int type;
    private boolean debug;
    private UserInfo userInfo;
    private Context context;
    private W_GlumeterListener w_glumeterListener;
    private AbstractWorker worker;
    private W_GluResult gluResult;
    private CMD01Bean mCMD01Bean;
    private String netstate;
    private NetUtil netUtil;
    private Map<String, Object> mapMCUcheck = new HashMap();
    private Map<String, Object> mapBluetoothcheck = new HashMap();
    private Map<String, Object> mapPiccheck = new HashMap();
    private String authentication;
    private Double updataId;
    private String MCUUpdateFilePaht;
    private String BluetoothUpdateFilePaht;
    private String PicUpdateFilePaht;
    private static volatile boolean updateRuning;
    private static volatile boolean measureRuning;
    private static volatile boolean timeCMD;
    private static volatile int updateType;
    private Total_BluetoothUpdateWorker total_bluetoothUpdateWorker;
    private Double fingerGlu;
    private String meal;
    private String eatType;
    private int userId;
    private String mealtime;
    private static volatile int historicalRecordpageNumber = 0;
    private Callback<ResponseResult> callbackGetAllCorrected = new Callback<ResponseResult>() {
        public void onResponse(Call<ResponseResult> call, Response<ResponseResult> response) {
            if (response.isSuccessful()) {
                ResponseResult body = (ResponseResult)response.body();
                if (body.getCode() == 20000) {
                    List<Double> corrects = (List)body.getData();
                    if (W_S_GlumeterWorker.this.userInfo != null) {
                        W_S_GlumeterWorker.this.userInfo.setChecksNet(corrects);
                        W_S_GlumeterWorker.this.log("请求标定值成功");
                    }
                } else {
                    W_S_GlumeterWorker.this.returnError(body.getCode(), body.getMessage());
                }
            }

        }

        public void onFailure(Call<ResponseResult> call, Throwable t) {
            W_S_GlumeterWorker.this.log("请求标定值失败");
        }
    };
    private Callback<ResponseResult> callbackUpdateUserInfo = new Callback<ResponseResult>() {
        public void onResponse(Call<ResponseResult> call, Response<ResponseResult> response) {
            if (response.isSuccessful()) {
                ResponseResult body = (ResponseResult)response.body();
                if (body.getCode() == 20000) {
                    W_S_GlumeterWorker.this.log("修改用户信息成功");
                    W_S_GlumeterWorker.this.W_fireGlumeterEvent(new W_GlumeterEvent(W_GlumeterEventType.UPDATEUSERINFOSUCCESS, (Object)null));
                } else {
                    W_S_GlumeterWorker.this.returnError(body.getCode(), body.getMessage());
                }
            }

        }

        public void onFailure(Call<ResponseResult> call, Throwable t) {
            W_S_GlumeterWorker.this.log("修改用户信息失败");
            W_S_GlumeterWorker.this.W_fireGlumeterEvent(new W_GlumeterEvent(W_GlumeterEventType.UPDATEUSERINFOFAIL, (Object)null));
        }
    };
    private Callback<ResponseResult> callbackcreateUser = new Callback<ResponseResult>() {
        public void onResponse(Call<ResponseResult> call, Response<ResponseResult> response) {
            if (response.isSuccessful()) {
                W_S_GlumeterWorker.this.log("上传用户数据成功");
                ResponseResult body = (ResponseResult)response.body();
                if (body.getCode() == 20000) {
                    if (body.getData() != null) {
                        long userId = ((Double)body.getData()).longValue();
                        W_S_GlumeterWorker.this.W_fireGlumeterEvent(new W_GlumeterEvent(W_GlumeterEventType.CREATEUSERINFOSUCCESS, userId + ""));
                    }
                } else {
                    W_S_GlumeterWorker.this.returnError(body.getCode(), body.getMessage());
                }
            }

        }

        public void onFailure(Call<ResponseResult> call, Throwable t) {
            W_S_GlumeterWorker.this.log("上传用户数据失败");
            W_S_GlumeterWorker.this.W_fireGlumeterEvent(new GlumeterEvent(GlumeterEventType.ERR_GETUSER, (Object)null));
        }
    };
    private Callback<ResponseResult> callbackUpdateData = new Callback<ResponseResult>() {
        public void onResponse(Call<ResponseResult> call, Response<ResponseResult> response) {
            if (response.isSuccessful()) {
                W_S_GlumeterWorker.this.log("上传原始数据请求成功");
                ResponseResult body = (ResponseResult)response.body();
                if (body.getCode() == 20000) {
                    W_S_GlumeterWorker.this.updataId = (Double)body.getData();
                } else {
                    W_S_GlumeterWorker.this.returnError(body.getCode(), body.getMessage());
                }
            }

        }

        public void onFailure(Call<ResponseResult> call, Throwable t) {
            W_S_GlumeterWorker.this.log("上传原始数据请求失败");
        }
    };
    private Callback<ResponseResult> updateFingerGluCallback = new Callback<ResponseResult>() {
        public void onResponse(Call<ResponseResult> call, Response<ResponseResult> response) {
            if (response.isSuccessful()) {
                W_S_GlumeterWorker.this.log("上传指尖血成功");
                ResponseResult body = (ResponseResult)response.body();
                if (body.getCode() == 20000) {
                    W_S_GlumeterWorker.this.log("上传指尖血成功返回数据:" + body.toString());
                } else {
                    W_S_GlumeterWorker.this.returnError(body.getCode(), body.getMessage());
                }
            }

        }

        public void onFailure(Call<ResponseResult> call, Throwable t) {
            W_S_GlumeterWorker.this.log("上传指尖血请求失败");
        }
    };
    private Callback<ResponseResultUpdate<RegisterResponseResult>> MCURegistercallback = new Callback<ResponseResultUpdate<RegisterResponseResult>>() {
        public void onResponse(Call<ResponseResultUpdate<RegisterResponseResult>> call, Response<ResponseResultUpdate<RegisterResponseResult>> response) {
            if (response.isSuccessful()) {
                W_S_GlumeterWorker.this.log("MCU网络请求注册成功");
                ResponseResultUpdate<RegisterResponseResult> responseResult = (ResponseResultUpdate)response.body();
                if (responseResult.getStatus() == 1000) {
                    RegisterResponseResult registerResponseResult = (RegisterResponseResult)responseResult.getData();
                    Map<String, String> mapregister = new HashMap();
                    mapregister.put("deviceId", registerResponseResult.getDeviceId());
                    mapregister.put("deviceSecret", registerResponseResult.getDeviceSecret());
                    if (W_S_GlumeterWorker.this.mCMD01Bean != null && W_S_GlumeterWorker.this.mCMD01Bean.getDeviceID() != null && W_S_GlumeterWorker.this.mCMD01Bean.getSoftwareVersionCode() != null) {
                        if ("A03".equals(W_S_GlumeterWorker.this.mCMD01Bean.getGhaDeviceType())) {
                            W_S_GlumeterWorker.this.netUtil.A03MCUCheck(W_S_GlumeterWorker.this.mCMD01Bean.getDeviceID(), W_S_GlumeterWorker.this.mCMD01Bean.getSoftwareVersionCode(), mapregister, W_S_GlumeterWorker.this.MCUCheckcallback);
                        } else if ("B03".equals(W_S_GlumeterWorker.this.mCMD01Bean.getGhaDeviceType())) {
                            W_S_GlumeterWorker.this.netUtil.B03MCUCheck(W_S_GlumeterWorker.this.mCMD01Bean.getDeviceID(), W_S_GlumeterWorker.this.mCMD01Bean.getSoftwareVersionCode(), mapregister, W_S_GlumeterWorker.this.MCUCheckcallback);
                        }
                    }
                }
            }

        }

        public void onFailure(Call<ResponseResultUpdate<RegisterResponseResult>> call, Throwable t) {
            W_S_GlumeterWorker.this.log("MCU网络请求注册失败" + t.getMessage());
        }
    };
    private Callback<ResponseResultUpdate<RegisterResponseResult>> BluetoothRegistercallback = new Callback<ResponseResultUpdate<RegisterResponseResult>>() {
        public void onResponse(Call<ResponseResultUpdate<RegisterResponseResult>> call, Response<ResponseResultUpdate<RegisterResponseResult>> response) {
            if (response.isSuccessful()) {
                W_S_GlumeterWorker.this.log("蓝牙网络请求注册成功");
                ResponseResultUpdate<RegisterResponseResult> responseResult = (ResponseResultUpdate)response.body();
                if (responseResult.getStatus() == 1000) {
                    RegisterResponseResult registerResponseResult = (RegisterResponseResult)responseResult.getData();
                    Map<String, String> mapregister = new HashMap();
                    mapregister.put("deviceId", registerResponseResult.getDeviceId());
                    mapregister.put("deviceSecret", registerResponseResult.getDeviceSecret());
                    if (W_S_GlumeterWorker.this.mCMD01Bean != null && W_S_GlumeterWorker.this.mCMD01Bean.getDeviceID() != null && W_S_GlumeterWorker.this.mCMD01Bean.getBluetooth_softwareVersionCode() != null) {
                        if ("A03".equals(W_S_GlumeterWorker.this.mCMD01Bean.getGhaDeviceType())) {
                            W_S_GlumeterWorker.this.netUtil.A03BluetoothCheck(W_S_GlumeterWorker.this.mCMD01Bean.getDeviceID(), W_S_GlumeterWorker.this.mCMD01Bean.getBluetooth_softwareVersionCode(), mapregister, W_S_GlumeterWorker.this.BluetoothCheckcallback);
                        } else if ("B03".equals(W_S_GlumeterWorker.this.mCMD01Bean.getGhaDeviceType())) {
                            W_S_GlumeterWorker.this.netUtil.B03BluetoothCheck(W_S_GlumeterWorker.this.mCMD01Bean.getDeviceID(), W_S_GlumeterWorker.this.mCMD01Bean.getBluetooth_softwareVersionCode(), mapregister, W_S_GlumeterWorker.this.BluetoothCheckcallback);
                        }
                    }
                }
            }

        }

        public void onFailure(Call<ResponseResultUpdate<RegisterResponseResult>> call, Throwable t) {
            W_S_GlumeterWorker.this.log("蓝牙网络请求注册失败" + t.getMessage());
        }
    };
    private Callback<ResponseResultUpdate<RegisterResponseResult>> PicRegistercallback = new Callback<ResponseResultUpdate<RegisterResponseResult>>() {
        public void onResponse(Call<ResponseResultUpdate<RegisterResponseResult>> call, Response<ResponseResultUpdate<RegisterResponseResult>> response) {
            if (response.isSuccessful()) {
                W_S_GlumeterWorker.this.log("图片网络请求注册成功");
                ResponseResultUpdate<RegisterResponseResult> responseResult = (ResponseResultUpdate)response.body();
                if (responseResult.getStatus() == 1000) {
                    RegisterResponseResult registerResponseResult = (RegisterResponseResult)responseResult.getData();
                    Map<String, String> mapregister = new HashMap();
                    mapregister.put("deviceId", registerResponseResult.getDeviceId());
                    mapregister.put("deviceSecret", registerResponseResult.getDeviceSecret());
                    if (W_S_GlumeterWorker.this.mCMD01Bean != null && W_S_GlumeterWorker.this.mCMD01Bean.getDeviceID() != null && W_S_GlumeterWorker.this.mCMD01Bean.getPicture_softwareVersionCode() != null) {
                        W_S_GlumeterWorker.this.netUtil.PicCheck(W_S_GlumeterWorker.this.mCMD01Bean.getDeviceID(), W_S_GlumeterWorker.this.mCMD01Bean.getPicture_softwareVersionCode(), mapregister, W_S_GlumeterWorker.this.PicCheckcallback);
                    }
                }
            }

        }

        public void onFailure(Call<ResponseResultUpdate<RegisterResponseResult>> call, Throwable t) {
            W_S_GlumeterWorker.this.log("图片网络请求注册失败" + t.getMessage());
        }
    };
    private Callback<ResponseResultUpdate<CheckResponseResult>> MCUCheckcallback = new Callback<ResponseResultUpdate<CheckResponseResult>>() {
        public void onResponse(Call<ResponseResultUpdate<CheckResponseResult>> call, Response<ResponseResultUpdate<CheckResponseResult>> response) {
            if (response.isSuccessful()) {
                W_S_GlumeterWorker.this.log("MCU网络请求检查成功");
                ResponseResultUpdate<CheckResponseResult> responseResult = (ResponseResultUpdate)response.body();
                if (responseResult.getStatus() == 1000) {
                    CheckResponseResult checkResponseResult = (CheckResponseResult)responseResult.getData();
                    CheckResponseResult.VersionBean versionBean = checkResponseResult.getVersion();
                    CheckResponseResult.ReleaseNotesBean releaseNotesBean = checkResponseResult.getReleaseNotes();
                    W_S_GlumeterWorker.this.mapMCUcheck.put("versionBean", versionBean);
                    W_S_GlumeterWorker.this.mapMCUcheck.put("releaseNotesBean", releaseNotesBean);
                    if (versionBean != null && W_S_GlumeterWorker.this.mCMD01Bean != null && W_S_GlumeterWorker.this.mCMD01Bean.getDeviceID() != null) {
                        Map<String, String> mapData = new HashMap();
                        mapData.put("mid", W_S_GlumeterWorker.this.mCMD01Bean.getDeviceID());
                        mapData.put("version", "2");
                        if ("A03".equals(W_S_GlumeterWorker.this.mCMD01Bean.getGhaDeviceType())) {
                            W_S_GlumeterWorker.this.netUtil.authA03MCU(mapData, W_S_GlumeterWorker.this.MCUauthcallback);
                        } else if ("B03".equals(W_S_GlumeterWorker.this.mCMD01Bean.getGhaDeviceType())) {
                            W_S_GlumeterWorker.this.netUtil.authB03MCU(mapData, W_S_GlumeterWorker.this.MCUauthcallback);
                        }

                        if (versionBean.getDeltaUrl() != null) {
                            W_S_GlumeterWorker.this.netUtil.FileDownload(versionBean.getDeltaUrl(), W_S_GlumeterWorker.this.MCUFileDowncallback);
                        }
                    }
                }
            }

        }

        public void onFailure(Call<ResponseResultUpdate<CheckResponseResult>> call, Throwable t) {
            W_S_GlumeterWorker.this.log("MCU检查请求失败" + t.getMessage());
        }
    };
    private Callback<ResponseResultUpdate<CheckResponseResult>> BluetoothCheckcallback = new Callback<ResponseResultUpdate<CheckResponseResult>>() {
        public void onResponse(Call<ResponseResultUpdate<CheckResponseResult>> call, Response<ResponseResultUpdate<CheckResponseResult>> response) {
            if (response.isSuccessful()) {
                W_S_GlumeterWorker.this.log("蓝牙网络请求检查成功");
                ResponseResultUpdate<CheckResponseResult> responseResult = (ResponseResultUpdate)response.body();
                if (responseResult.getStatus() == 1000) {
                    CheckResponseResult checkResponseResult = (CheckResponseResult)responseResult.getData();
                    CheckResponseResult.VersionBean versionBean = checkResponseResult.getVersion();
                    CheckResponseResult.ReleaseNotesBean releaseNotesBean = checkResponseResult.getReleaseNotes();
                    W_S_GlumeterWorker.this.mapBluetoothcheck.put("versionBean", versionBean);
                    W_S_GlumeterWorker.this.mapBluetoothcheck.put("releaseNotesBean", releaseNotesBean);
                    if (versionBean != null && versionBean.getDeltaUrl() != null) {
                        W_S_GlumeterWorker.this.netUtil.FileDownload(versionBean.getDeltaUrl(), W_S_GlumeterWorker.this.BluetoothFileDowncallback);
                    }
                }
            }

        }

        public void onFailure(Call<ResponseResultUpdate<CheckResponseResult>> call, Throwable t) {
            W_S_GlumeterWorker.this.log("蓝牙检查请求失败" + t.getMessage());
        }
    };
    private Callback<ResponseResultUpdate<CheckResponseResult>> PicCheckcallback = new Callback<ResponseResultUpdate<CheckResponseResult>>() {
        public void onResponse(Call<ResponseResultUpdate<CheckResponseResult>> call, Response<ResponseResultUpdate<CheckResponseResult>> response) {
            if (response.isSuccessful()) {
                W_S_GlumeterWorker.this.log("图片网络请求检查成功");
                ResponseResultUpdate<CheckResponseResult> responseResult = (ResponseResultUpdate)response.body();
                if (responseResult.getStatus() == 1000) {
                    CheckResponseResult checkResponseResult = (CheckResponseResult)responseResult.getData();
                    CheckResponseResult.VersionBean versionBean = checkResponseResult.getVersion();
                    CheckResponseResult.ReleaseNotesBean releaseNotesBean = checkResponseResult.getReleaseNotes();
                    W_S_GlumeterWorker.this.mapPiccheck.put("versionBean", versionBean);
                    W_S_GlumeterWorker.this.mapPiccheck.put("releaseNotesBean", releaseNotesBean);
                    if (versionBean != null && versionBean.getDeltaUrl() != null) {
                        W_S_GlumeterWorker.this.netUtil.FileDownload(versionBean.getDeltaUrl(), W_S_GlumeterWorker.this.PicFileDowncallback);
                    }
                }
            }

        }

        public void onFailure(Call<ResponseResultUpdate<CheckResponseResult>> call, Throwable t) {
            W_S_GlumeterWorker.this.log("图片请求失败" + t.getMessage());
        }
    };
    private Callback<ResponseResultUpdate> MCUauthcallback = new Callback<ResponseResultUpdate>() {
        public void onResponse(Call<ResponseResultUpdate> call, Response<ResponseResultUpdate> response) {
            if (response.isSuccessful()) {
                ResponseResultUpdate body = (ResponseResultUpdate)response.body();
                if (body.getStatus() == 1000) {
                    W_S_GlumeterWorker.this.log("MCU鉴权码请求成功");
                    W_S_GlumeterWorker.this.authentication = (String)body.getData();
                }
            }

        }

        public void onFailure(Call<ResponseResultUpdate> call, Throwable t) {
            W_S_GlumeterWorker.this.log("MCU鉴权码请求失败");
        }
    };
    private Callback<ResponseBody> MCUFileDowncallback = new Callback<ResponseBody>() {
        public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {
            final ResponseBody body = (ResponseBody)response.body();
            W_S_GlumeterWorker.this.log("MCU文件下载请求成功");
            if (response.isSuccessful()) {
                W_S_GlumeterWorker.this.log("服务器联系并有MCU文件" + response.message() + " " + body.contentLength());
                (new Thread() {
                    public void run() {
                        boolean filecreate = false;

                        try {
                            String path = W_S_GlumeterWorker.this.context.getFilesDir() + "/";
                            CheckResponseResult.VersionBean versionBean = (CheckResponseResult.VersionBean)W_S_GlumeterWorker.this.mapMCUcheck.get("versionBean");
                            String Name = W_S_GlumeterWorker.this.mCMD01Bean.getGhaDeviceType() + "MCU" + versionBean.getVersionName() + ".zip";
                            File file = new File(path, Name);
                            filecreate = file.createNewFile();
                            if (filecreate) {
                                W_S_GlumeterWorker.this.log("MCU文件创建成功");
                            }

                            FileOutputStream outputStream = new FileOutputStream(file);
                            if (outputStream != null) {
                                outputStream.write(body.bytes());
                                outputStream.flush();
                                outputStream.close();
                            }

                            W_S_GlumeterWorker.this.log("MCU文件写成功");
                            W_S_GlumeterWorker.this.log("文件路径:" + file.getAbsolutePath());
                            W_S_GlumeterWorker.this.MCUUpdateFilePaht = file.getAbsolutePath();
                            W_S_GlumeterWorker.this.updateReal();
                        } catch (IOException var7) {
                            var7.printStackTrace();
                        }

                    }
                }).start();
            } else {
                W_S_GlumeterWorker.this.log("MCU联系服务器失败");
            }

        }

        public void onFailure(Call<ResponseBody> call, Throwable t) {
            W_S_GlumeterWorker.this.log("MCU文件下载请求失败" + t.getMessage());
        }
    };
    private Callback<ResponseBody> BluetoothFileDowncallback = new Callback<ResponseBody>() {
        public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {
            final ResponseBody body = (ResponseBody)response.body();
            W_S_GlumeterWorker.this.log("蓝牙文件下载请求成功");
            if (response.isSuccessful()) {
                W_S_GlumeterWorker.this.log("服务器联系并有蓝牙文件" + response.message() + " " + body.contentLength());
                (new Thread() {
                    public void run() {
                        boolean filecreate = false;

                        try {
                            String path = W_S_GlumeterWorker.this.context.getFilesDir() + "/";
                            CheckResponseResult.VersionBean versionBean = (CheckResponseResult.VersionBean)W_S_GlumeterWorker.this.mapBluetoothcheck.get("versionBean");
                            String Name = W_S_GlumeterWorker.this.mCMD01Bean.getGhaDeviceType() + "Bluetooth" + versionBean.getVersionName() + ".zip";
                            File file = new File(path, Name);
                            filecreate = file.createNewFile();
                            if (filecreate) {
                                W_S_GlumeterWorker.this.log("蓝牙文件创建成功");
                            }

                            FileOutputStream outputStream = new FileOutputStream(file);
                            if (outputStream != null) {
                                outputStream.write(body.bytes());
                                outputStream.flush();
                                outputStream.close();
                            }

                            W_S_GlumeterWorker.this.log("蓝牙文件写成功");
                            W_S_GlumeterWorker.this.BluetoothUpdateFilePaht = file.getAbsolutePath();
                            W_S_GlumeterWorker.this.updateReal();
                        } catch (IOException var7) {
                            var7.printStackTrace();
                        }

                    }
                }).start();
            } else {
                W_S_GlumeterWorker.this.log("蓝牙联系服务器失败");
            }

        }

        public void onFailure(Call<ResponseBody> call, Throwable t) {
            W_S_GlumeterWorker.this.log("蓝牙文件下载请求失败" + t.getMessage());
        }
    };
    private Callback<ResponseBody> PicFileDowncallback = new Callback<ResponseBody>() {
        public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {
            final ResponseBody body = (ResponseBody)response.body();
            W_S_GlumeterWorker.this.log("图片文件下载请求成功");
            if (response.isSuccessful()) {
                W_S_GlumeterWorker.this.log("服务器联系并有图片文件" + response.message() + " " + body.contentLength());
                (new Thread() {
                    public void run() {
                        boolean filecreate = false;

                        try {
                            String path = W_S_GlumeterWorker.this.context.getFilesDir() + "/";
                            CheckResponseResult.VersionBean versionBean = (CheckResponseResult.VersionBean)W_S_GlumeterWorker.this.mapPiccheck.get("versionBean");
                            String Name = W_S_GlumeterWorker.this.mCMD01Bean.getGhaDeviceType() + "Picture" + versionBean.getVersionName() + ".zip";
                            File file = new File(path, Name);
                            filecreate = file.createNewFile();
                            if (filecreate) {
                                W_S_GlumeterWorker.this.log("图片文件创建成功");
                            }

                            FileOutputStream outputStream = new FileOutputStream(file);
                            if (outputStream != null) {
                                outputStream.write(body.bytes());
                                outputStream.flush();
                                outputStream.close();
                            }

                            W_S_GlumeterWorker.this.log("图片文件写成功");
                            W_S_GlumeterWorker.this.PicUpdateFilePaht = file.getAbsolutePath();
                            W_S_GlumeterWorker.this.updateReal();
                        } catch (IOException var7) {
                            var7.printStackTrace();
                        }

                    }
                }).start();
            } else {
                W_S_GlumeterWorker.this.log("图片联系服务器失败");
            }

        }

        public void onFailure(Call<ResponseBody> call, Throwable t) {
            W_S_GlumeterWorker.this.log("图片文件下载请求失败" + t.getMessage());
        }
    };
    private GlumeterListener listener = new GlumeterListener() {
        public void onEvent(GlumeterEvent event) {
            if (event.getType() == GlumeterEventType.PRC_DEVICES) {
                ArrayList<BleRssiDevice> bleRssiDevices = (ArrayList)event.getContent();
                W_S_GlumeterWorker.this.log("搜索到设备:" + bleRssiDevices);
                W_S_GlumeterWorker.this.W_fireGlumeterEvent(new GlumeterEvent(GlumeterEventType.PRC_DEVICES, bleRssiDevices));
            }

            if (event.getType() == GlumeterEventType.ERR_NDEV) {
                W_S_GlumeterWorker.this.log("设备不存在没有搜索到设备");
                W_S_GlumeterWorker.this.W_fireGlumeterEvent(new GlumeterEvent(GlumeterEventType.ERR_NDEV, (Object)null));
            }

            if (event.getType() == GlumeterEventType.CONNECTED) {
                W_S_GlumeterWorker.this.log("连接成功");
                W_S_GlumeterWorker.this.W_fireGlumeterEvent(new GlumeterEvent(GlumeterEventType.CONNECTED, (Object)null));
            }

            if (event.getType() == GlumeterEventType.CONNECTTING) {
                W_S_GlumeterWorker.this.log("正在连接");
                W_S_GlumeterWorker.this.W_fireGlumeterEvent(new GlumeterEvent(GlumeterEventType.CONNECTTING, (Object)null));
            }

            if (event.getType() == GlumeterEventType.DISCONNECTED) {
                W_S_GlumeterWorker.this.log("未连接");
                W_S_GlumeterWorker.this.W_fireGlumeterEvent(new GlumeterEvent(GlumeterEventType.DISCONNECTED, (Object)null));
            }

            if (event.getType() == GlumeterEventType.PRC_INITTIME) {
                W_S_GlumeterWorker.this.log("同步时间完成");
                W_S_GlumeterWorker.this.mCMD01Bean = (CMD01Bean)event.getContent();
                InitTimeBean timeBean = new InitTimeBean();
                timeBean.setDeviceID(W_S_GlumeterWorker.this.mCMD01Bean.getDeviceID());
                timeBean.setBatteryLevel(W_S_GlumeterWorker.this.mCMD01Bean.getBatteryLevel());
                timeBean.setRun_type(W_S_GlumeterWorker.this.mCMD01Bean.getRun_type());
                W_S_GlumeterWorker.this.W_fireGlumeterEvent(new GlumeterEvent(GlumeterEventType.PRC_INITTIME, timeBean));
                if (!W_S_GlumeterWorker.timeCMD) {
                    W_S_GlumeterWorker.this.checkUpdate();
                }

                W_S_GlumeterWorker.timeCMD = true;
            }

            if (event.getType() == GlumeterEventType.PRC_FINISH) {
                W_S_GlumeterWorker.this.log("测试结束,资源释放");
                W_S_GlumeterWorker.this.W_fireGlumeterEvent(new GlumeterEvent(GlumeterEventType.PRC_FINISH, (Object)null));
            }

            if (event.getType() == GlumeterEventType.PRC_RESULT) {
                GluReault result = (GluReault)event.getContent();
                W_S_GlumeterWorker.this.log("接收测试结果:" + result.toString());
                W_S_GlumeterWorker.this.gluResult = new W_GluResult();
                W_S_GlumeterWorker.this.gluResult.setDeviceID(result.getDeviceID());
                W_S_GlumeterWorker.this.gluResult.setGlucose(result.getCheckGlu());
                W_S_GlumeterWorker.this.gluResult.setMeasureTime(result.getMeasureTime());
            }

            if (event.getType() == GlumeterEventType.PRC_INIT) {
                W_S_GlumeterWorker.this.log("初始化进程");
                W_S_GlumeterWorker.this.W_fireGlumeterEvent(new GlumeterEvent(GlumeterEventType.PRC_INIT, (Object)null));
            }

            if (event.getType() == GlumeterEventType.PRC_READY) {
                W_S_GlumeterWorker.this.log("设备准备完成");
                W_S_GlumeterWorker.this.W_fireGlumeterEvent(new GlumeterEvent(GlumeterEventType.PRC_READY, (Object)null));
            }

            if (event.getType() == GlumeterEventType.ERR_USER) {
                W_S_GlumeterWorker.this.log("没有存储该用户信息,请重新测试");
                W_S_GlumeterWorker.this.W_fireGlumeterEvent(new GlumeterEvent(GlumeterEventType.ERR_USER, (Object)null));
            }

            if (event.getType() == GlumeterEventType.ERR_FINGER) {
                W_S_GlumeterWorker.this.log("环境温度正常,可以插入手指了");
                W_S_GlumeterWorker.this.W_fireGlumeterEvent(new GlumeterEvent(GlumeterEventType.ERR_FINGER, (Object)null));
            }

            if (event.getType() == GlumeterEventType.ERR_SZER_TL) {
                W_S_GlumeterWorker.this.log("手指温度偏低");
                W_S_GlumeterWorker.this.W_fireGlumeterEvent(new GlumeterEvent(GlumeterEventType.ERR_SZER_TL, (Object)null));
            }

            if (event.getType() == GlumeterEventType.ERR_SZER_TH) {
                W_S_GlumeterWorker.this.log("手指温度偏高");
                W_S_GlumeterWorker.this.W_fireGlumeterEvent(new GlumeterEvent(GlumeterEventType.ERR_SZER_TH, (Object)null));
            }

            if (event.getType() == GlumeterEventType.ERR_HJER_ETL) {
                W_S_GlumeterWorker.this.log("环境温度偏低");
                W_S_GlumeterWorker.this.W_fireGlumeterEvent(new GlumeterEvent(GlumeterEventType.ERR_HJER_ETL, (Object)null));
            }

            if (event.getType() == GlumeterEventType.ERR_HJER_ETH) {
                W_S_GlumeterWorker.this.log("环境温度偏高");
                W_S_GlumeterWorker.this.W_fireGlumeterEvent(new GlumeterEvent(GlumeterEventType.ERR_HJER_ETH, (Object)null));
            }

            if (event.getType() == GlumeterEventType.ERR_HJER_EHH) {
                W_S_GlumeterWorker.this.log("环境湿度偏高");
                W_S_GlumeterWorker.this.W_fireGlumeterEvent(new GlumeterEvent(GlumeterEventType.ERR_HJER_EHH, (Object)null));
            }

            if (event.getType() == GlumeterEventType.ERR_HJER_EHL) {
                W_S_GlumeterWorker.this.log("环境湿度偏低");
                W_S_GlumeterWorker.this.W_fireGlumeterEvent(new GlumeterEvent(GlumeterEventType.ERR_HJER_EHL, (Object)null));
            }

            if (event.getType() == GlumeterEventType.ERR_HJER) {
                W_S_GlumeterWorker.this.log("环境条件不符");
                W_S_GlumeterWorker.this.W_fireGlumeterEvent(new GlumeterEvent(GlumeterEventType.ERR_HJER, (Object)null));
            }

            if (event.getType() == GlumeterEventType.ERR_DEVICE) {
                W_S_GlumeterWorker.this.log("设备故障,请联系维修");
                W_S_GlumeterWorker.this.W_fireGlumeterEvent(new GlumeterEvent(GlumeterEventType.ERR_DEVICE, (Object)null));
            }

            if (event.getType() == GlumeterEventType.ERR_FINGERIN) {
                W_S_GlumeterWorker.this.W_fireGlumeterEvent(new GlumeterEvent(GlumeterEventType.ERR_FINGERIN, (Object)null));
                W_S_GlumeterWorker.this.log("手指已经放入");
            }

            if (event.getType() == GlumeterEventType.PRC_BEGIN) {
                W_S_GlumeterWorker.this.log("测量开始了");
                W_S_GlumeterWorker.this.W_fireGlumeterEvent(new GlumeterEvent(GlumeterEventType.PRC_BEGIN, (Object)null));
            }

            if (event.getType() == GlumeterEventType.ERR_FNGR) {
                W_S_GlumeterWorker.this.W_fireGlumeterEvent(new GlumeterEvent(GlumeterEventType.ERR_FNGR, (Object)null));
                W_S_GlumeterWorker.this.log("未检测到手指");
            }

            String testproces;
            if (event.getType() == GlumeterEventType.PRC_DATA) {
                testproces = (String)event.getContent();
                W_S_GlumeterWorker.this.log("测试完成");
                W_S_GlumeterWorker.this.W_fireGlumeterEvent(new GlumeterEvent(GlumeterEventType.PRC_PROCESS, testproces));
            }

            if (event.getType() == GlumeterEventType.ERR_ERRO) {
                W_S_GlumeterWorker.this.log("手指已拔出");
                W_S_GlumeterWorker.this.W_fireGlumeterEvent(new GlumeterEvent(GlumeterEventType.ERR_ERRO, (Object)null));
            }

            if (event.getType() == GlumeterEventType.PRC_PROCESS) {
                testproces = (String)event.getContent();
                W_S_GlumeterWorker.this.log("测试中 》》" + testproces);
                W_S_GlumeterWorker.this.W_fireGlumeterEvent(new GlumeterEvent(GlumeterEventType.PRC_PROCESS, testproces));
            }

            if (event.getType() == GlumeterEventType.PRC_INITDATASTART) {
                W_S_GlumeterWorker.this.log("中间数据开始上传>>>");
            }

            if (event.getType() == GlumeterEventType.PRC_INITDATA) {
                W_S_GlumeterWorker.this.log("原始数据同步完成/没有需同步文件");
            }

            if (event.getType() == GlumeterEventType.PRC_INITDATARESULT) {
                OriginalDataBean beanx = (OriginalDataBean)event.getContent();
                W_S_GlumeterWorker.this.log("收到一个原始数据文件" + beanx.toString() + " " + beanx.getOriginalDataSize() + " 接收时间:" + beanx.getReceivetime());
                if (!TextUtils.isEmpty(W_S_GlumeterWorker.this.netstate)) {
                    W_S_GlumeterWorker.this.netUpdate(beanx);
                }
            }

            if (event.getType() == GlumeterEventType.PRC_INITDATAFINISH) {
                W_S_GlumeterWorker.this.log("原始数据同步完成");
                W_S_GlumeterWorker.this.W_fireGlumeterEvent(new GlumeterEvent(GlumeterEventType.PRC_INITDATAFINISH, W_S_GlumeterWorker.this.gluResult));
                W_S_GlumeterWorker.measureRuning = false;
            }

            if (event.getType() == GlumeterEventType.PRC_UPDATESTART) {
                W_S_GlumeterWorker.this.log("程序升级开始");
                W_S_GlumeterWorker.this.W_fireGlumeterEvent(new GlumeterEvent(GlumeterEventType.PRC_UPDATESTART, (Object)null));
            }

            if (event.getType() == GlumeterEventType.PRC_UPDATE) {
                long time = (Long)event.getContent();
                W_S_GlumeterWorker.this.log("程序升级完成，发送数据成功,用时=" + time);
                File filex;
                if (W_S_GlumeterWorker.updateType == 1) {
                    filex = new File(W_S_GlumeterWorker.this.MCUUpdateFilePaht);
                    filex.delete();
                }

                if (W_S_GlumeterWorker.updateType == 3) {
                    filex = new File(W_S_GlumeterWorker.this.PicUpdateFilePaht);
                    filex.delete();
                }

                if (W_S_GlumeterWorker.updateType == 2) {
                    filex = new File(W_S_GlumeterWorker.this.BluetoothUpdateFilePaht);
                    filex.delete();
                }

                W_S_GlumeterWorker.this.W_fireGlumeterEvent(new GlumeterEvent(GlumeterEventType.PRC_UPDATE, time));
                W_S_GlumeterWorker.this.update();
            }

            if (event.getType() == GlumeterEventType.PRC_UPDATE_PRO) {
                W_S_GlumeterWorker.this.log("\n程序升级进度" + event.getContent());
                int pro = (Integer)event.getContent();
                W_S_GlumeterWorker.this.W_fireGlumeterEvent(new GlumeterEvent(GlumeterEventType.PRC_UPDATE_PRO, pro));
            }

            if (event.getType() == GlumeterEventType.ERR_UPDATE) {
                W_S_GlumeterWorker.this.log("\n程序升级失败,升级错误，收到非法指令");
                W_S_GlumeterWorker.this.W_fireGlumeterEvent(new GlumeterEvent(GlumeterEventType.ERR_UPDATE, (Object)null));
            }

            if (event.getType() == GlumeterEventType.ERR_UPDATE_TYPE) {
                W_S_GlumeterWorker.this.log("\n程序升级非法的升级类型");
            }

            if (event.getType() == GlumeterEventType.ERR_UPDATE_NO_AUTHORIZATIONCODE) {
                W_S_GlumeterWorker.this.log("\n程序升级MCU升级没有输入鉴权码");
            }

            if (event.getType() == GlumeterEventType.ERR_UPDATE_NO_FILE) {
                W_S_GlumeterWorker.this.log("\n程序升级未发现升级文件");
            }

            if (event.getType() == GlumeterEventType.ERR_UPDATE_NO_MD5) {
                W_S_GlumeterWorker.this.log("\n程序升级未发现MD5");
            }

            if (event.getType() == GlumeterEventType.PRC_BLUETOOTH_UPDATE_START) {
                W_S_GlumeterWorker.this.log("\n蓝牙开始升级");
                W_S_GlumeterWorker.this.W_fireGlumeterEvent(new GlumeterEvent(GlumeterEventType.PRC_BLUETOOTH_UPDATE_START, (Object)null));
            }

            if (event.getType() == GlumeterEventType.PRC_BLUETOOTH_UPDATE_PRO) {
                ProgressBean bean = (ProgressBean)event.getContent();
                W_S_GlumeterWorker.this.log("\n蓝牙升级进度=" + bean.getPercent() + "\nspeed=" + bean.getSpeed() + "avgSpeed=" + bean.getAvgSpeed());
                W_S_GlumeterWorker.this.W_fireGlumeterEvent(new GlumeterEvent(GlumeterEventType.PRC_BLUETOOTH_UPDATE_PRO, bean));
            }

            if (event.getType() == GlumeterEventType.PRC_BLUETOOTH_UPDATE_FAIL) {
                W_S_GlumeterWorker.this.log("\n蓝牙升级失败");
                W_S_GlumeterWorker.this.W_fireGlumeterEvent(new GlumeterEvent(GlumeterEventType.PRC_BLUETOOTH_UPDATE_FAIL, (Object)null));
            }

            if (event.getType() == GlumeterEventType.PRC_BLUETOOTH_UPDATE_FINISH) {
                W_S_GlumeterWorker.this.log("\n蓝牙升级完成");
                if (W_S_GlumeterWorker.this.total_bluetoothUpdateWorker != null) {
                    W_S_GlumeterWorker.this.total_bluetoothUpdateWorker.close();
                }

                File file;
                if (W_S_GlumeterWorker.updateType == 1) {
                    file = new File(W_S_GlumeterWorker.this.MCUUpdateFilePaht);
                    file.delete();
                }

                if (W_S_GlumeterWorker.updateType == 3) {
                    file = new File(W_S_GlumeterWorker.this.PicUpdateFilePaht);
                    file.delete();
                }

                if (W_S_GlumeterWorker.updateType == 2) {
                    file = new File(W_S_GlumeterWorker.this.BluetoothUpdateFilePaht);
                    file.delete();
                }

                W_S_GlumeterWorker.this.W_fireGlumeterEvent(new GlumeterEvent(GlumeterEventType.PRC_BLUETOOTH_UPDATE_FINISH, (Object)null));
                W_S_GlumeterWorker.this.update();
            }

            if (event.getType() == GlumeterEventType.PRC_BLUETOOTH_UPDATE_ERROR) {
                W_S_GlumeterWorker.this.log("\n升级错误=" + event.getContent());
                W_S_GlumeterWorker.this.W_fireGlumeterEvent(new GlumeterEvent(GlumeterEventType.PRC_BLUETOOTH_UPDATE_ERROR, (Object)null));
            }

            if (event.getType() == GlumeterEventType.PRC_BLUETOOTH_UPDATE_STOP) {
                W_S_GlumeterWorker.this.log("\n升级停止");
                W_S_GlumeterWorker.this.W_fireGlumeterEvent(new GlumeterEvent(GlumeterEventType.PRC_BLUETOOTH_UPDATE_STOP, (Object)null));
            }

        }
    };

    private void returnError(int code, String message) {
        this.W_fireGlumeterEvent(new W_GlumeterEvent(W_GlumeterEventType.NETERROR, code + "-" + message));
    }

    public W_S_GlumeterWorker(Context context, W_GlumeterListener listener) {
        this.context = context;
        this.w_glumeterListener = listener;
        this.debug = true;
        this.netstate = NetworkUtil.getNetworkState(context);
        if (!TextUtils.isEmpty(this.netstate)) {
            this.netUtil = new NetUtil(this.netstate);
            this.netUtil.setDebug(false);
        } else {
            this.W_fireGlumeterEvent(new W_GlumeterEvent(W_GlumeterEventType.NONET, (Object)null));
        }

    }

    public void configure(Map<String, Object> map) throws Exception {
        String userId = null;
        String mealtime = null;
        if (map.get("userId") == null) {
            throw new IllegalArgumentException("用户ID(userId)为空(null)");
        } else if (map.get("userId") instanceof String) {
            userId = (String)map.get("userId");
            if (map.get("mealtime") == null) {
                throw new IllegalArgumentException("用户用餐时间(mealtime)为空(null)");
            } else if (map.get("mealtime") instanceof String) {
                mealtime = (String)map.get("mealtime");
                this.userInfo = this.checkUserInfo(map);
                this.userInfo.setUserId(userId);
                this.userInfo.setMealtime(mealtime);
                this.getAllCorrected(Long.valueOf(userId));
                int[] mealEat = MealUtil.getMealStateType(this.userInfo.getDiabetes(), mealtime);
                this.meal = mealEat[1] + "";
                this.eatType = mealEat[0] + "";
                this.userInfo.setMeal(this.meal);
                this.userInfo.setEatType(this.eatType);
                this.log("传入的用户信息：" + this.userInfo.toString());
            } else {
                throw new IllegalArgumentException("用户用餐时间(mealtime)非字符串类型");
            }
        } else {
            throw new IllegalArgumentException("用户ID(userId)非字符串类型");
        }
    }

    public void createUser(Map<String, Object> map) throws Exception {
        UserInfo userInfo = this.checkUserInfo(map);
        if (!TextUtils.isEmpty(this.netstate)) {
            this.netGetUserID(userInfo);
        }

    }

    private UserInfo checkUserInfo(Map<String, Object> map) throws Exception {
        String medication = null;
        String medicationjs = null;
        if (map.get("userName") == null) {
            throw new IllegalArgumentException("用户名(userName)为空(null)");
        } else if (map.get("userName") instanceof String) {
            String userName = (String)map.get("userName");
            if (map.get("birthday") == null) {
                throw new IllegalArgumentException("用户出生日期(birthday)为空(null)");
            } else if (map.get("birthday") instanceof String) {
                String fpg_temp = (String)map.get("birthday");
                if (!NumberUtil.isBirthday(fpg_temp)) {
                    throw new IllegalArgumentException("用户出生日期(birthday)为非法类型");
                } else {
                    Integer _age = getAge(fpg_temp);
                    if (_age > 99) {
                        _age = 99;
                    }

                    if (_age < 0) {
                        throw new IllegalArgumentException("用户年龄(age)小于0，年龄异常");
                    } else {
                        String birthday = fpg_temp;
                        if (map.get("gender") == null) {
                            throw new IllegalArgumentException("用户性别(gender)为空(null)");
                        } else if (map.get("gender") instanceof String) {
                            fpg_temp = (String)map.get("gender");
                            if (!NumberUtil.isgender(fpg_temp)) {
                                throw new IllegalArgumentException("用户性别(gender)为非法类型");
                            } else {
                                int gender = Integer.valueOf(fpg_temp);
                                if (map.get("height") == null) {
                                    throw new IllegalArgumentException("用户身高(height)为空(null)");
                                } else if (map.get("height") instanceof String) {
                                    fpg_temp = (String)map.get("height");
                                    if (!NumberUtil.isNumeric(fpg_temp)) {
                                        throw new IllegalArgumentException("用户身高(height)为非法类型");
                                    } else {
                                        Integer height = Integer.valueOf(fpg_temp);
                                        if (height >= 130 && height <= 210) {
                                            if (map.get("weight") == null) {
                                                throw new IllegalArgumentException("用户体重(weight)为空(null)");
                                            } else if (map.get("weight") instanceof String) {
                                                fpg_temp = (String)map.get("weight");
                                                if (!NumberUtil.isNumeric(fpg_temp)) {
                                                    throw new IllegalArgumentException("用户体重(weight)为非法类型");
                                                } else {
                                                    Integer weight = Integer.valueOf(fpg_temp);
                                                    if (weight >= 30 && weight <= 150) {
                                                        if (map.get("diabetes") == null) {
                                                            throw new IllegalArgumentException("用户糖尿病类型(diabetes)为空(null)");
                                                        } else if (map.get("diabetes") instanceof String) {
                                                            fpg_temp = (String)map.get("diabetes");
                                                            if (!NumberUtil.isDiabetes(fpg_temp)) {
                                                                throw new IllegalArgumentException("用户糖尿病类型(diabetes)为非法类型");
                                                            } else {
                                                                Integer diabetes = Integer.valueOf(fpg_temp);
                                                                if (map.get("fpg") == null) {
                                                                    throw new IllegalArgumentException("用户空腹血糖(fpg)为空(null)");
                                                                } else if (map.get("fpg") instanceof String) {
                                                                    fpg_temp = (String)map.get("fpg");
                                                                    if (!NumberUtil.isDoubleOrFloat(fpg_temp)) {
                                                                        throw new IllegalArgumentException("用户空腹血糖(fpg)为非法类型");
                                                                    } else {
                                                                        Double fpg = Double.valueOf(fpg_temp);
                                                                        if (!(fpg < 3.0) && !(fpg > 20.9)) {
                                                                            if (map.get("medication") != null) {
                                                                                if (!(map.get("medication") instanceof ArrayList)) {
                                                                                    throw new IllegalArgumentException("用户用药情况(medication)非List类型");
                                                                                }

                                                                                ArrayList<Drug> drugs = (ArrayList)map.get("medication");
                                                                                medicationjs = this.getMedicationjs(drugs);
                                                                                medication = this.getMedication(drugs);
                                                                            }

                                                                            UserInfo userInfo = new UserInfo();
                                                                            userInfo.setUserName(userName);
                                                                            userInfo.setBrithday(birthday);
                                                                            userInfo.setAge(_age);
                                                                            userInfo.setGender(gender);
                                                                            userInfo.setDiabetes(diabetes);
                                                                            userInfo.setHeight(height);
                                                                            userInfo.setWeight(weight);
                                                                            userInfo.setFpg(fpg);
                                                                            userInfo.setMedication(medication);
                                                                            userInfo.setMedicationjs(medicationjs);
                                                                            return userInfo;
                                                                        } else {
                                                                            throw new IllegalArgumentException("用户空腹血糖(fpg)超出正常范围(3.0-20.9)");
                                                                        }
                                                                    }
                                                                } else {
                                                                    throw new IllegalArgumentException("用户空腹血糖(fpg)非字符串类型");
                                                                }
                                                            }
                                                        } else {
                                                            throw new IllegalArgumentException("用户糖尿病类型(diabetes)非字符串类型");
                                                        }
                                                    } else {
                                                        throw new IllegalArgumentException("用户体重(weight)超出正常范围(30-150kg)");
                                                    }
                                                }
                                            } else {
                                                throw new IllegalArgumentException("用户体重(weight)非字符串类型");
                                            }
                                        } else {
                                            throw new IllegalArgumentException("用户身高(height)超出正常范围(130-210cm)");
                                        }
                                    }
                                } else {
                                    throw new IllegalArgumentException("用户身高(height)非字符串类型");
                                }
                            }
                        } else {
                            throw new IllegalArgumentException("用户性别(gender)非字符串类型");
                        }
                    }
                }
            } else {
                throw new IllegalArgumentException("用户出生日期(birthday)非字符串类型");
            }
        } else {
            throw new IllegalArgumentException("用户名(userName)非字符串类型");
        }
    }

    private void getAllCorrected(long userId) {
        if (this.netUtil != null) {
            this.netUtil.getAllCorrected(userId, this.callbackGetAllCorrected);
        }

    }
    public static Integer getAge(String date) {
        return getAge(dateToTimestamp(date));
    }

    public static long dateToTimestamp(String date) {
        SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMdd");
        Date datet = null;

        try {
            datet = formatter.parse(date);
        } catch (ParseException var5) {
            var5.printStackTrace();
        }

        long time = datet.getTime();
        return time;
    }

    public static Integer getAge(Long birth) {
        if (birth == null) {
            return null;
        } else {
            Long now = System.currentTimeMillis();
            if (birth > now) {
                return 0;
            } else{
                Double age = Math.ceil((double)((now - birth) / 31536000000L));
                return age.intValue();
            }
        }
    }

    public void updateUserInfo(Map<String, Object> map) {
        Integer userId = null;
        String userName = null;
        String birthday = null;
        Integer gender = null;
        Double height = null;
        Double weight = null;
        Integer diabetes = null;
        Double fpg = null;
        String medicationjs = null;
        if (map.get("userId") == null) {
            throw new IllegalArgumentException("用户ID(userId)为空(null)");
        } else if (!(map.get("userId") instanceof String)) {
            throw new IllegalArgumentException("用户ID(userId)非字符串类型");
        } else {
            userId = Integer.valueOf((String)map.get("userId"));
            if (map.get("userName") != null) {
                if (!(map.get("userName") instanceof String)) {
                    throw new IllegalArgumentException("用户名(userName)非字符串类型");
                }

                userName = (String)map.get("userName");
            }

            String fpg_temp;
            if (map.get("birthday") != null) {
                if (!(map.get("birthday") instanceof String)) {
                    throw new IllegalArgumentException("用户出生日期(birthday)非字符串类型");
                }

                fpg_temp = (String)map.get("birthday");
                if (!NumberUtil.isBirthday(fpg_temp)) {
                    throw new IllegalArgumentException("用户出生日期(birthday)为非法类型");
                }

                Integer _age = NumberUtil.getAge(fpg_temp);
                if (_age > 99) {
                    _age = 99;
                }

                if (_age < 18) {
                    throw new IllegalArgumentException("用户年龄(age)小于18，未成年人不可检测");
                }

                birthday = fpg_temp;
            }

            if (map.get("gender") != null) {
                if (!(map.get("gender") instanceof String)) {
                    throw new IllegalArgumentException("用户性别(gender)非字符串类型");
                }

                fpg_temp = (String)map.get("gender");
                if (!NumberUtil.isgender(fpg_temp)) {
                    throw new IllegalArgumentException("用户性别(gender)为非法类型");
                }

                gender = Integer.valueOf(fpg_temp);
            }

            if (map.get("height") != null) {
                if (!(map.get("height") instanceof String)) {
                    throw new IllegalArgumentException("用户身高(height)非字符串类型");
                }

                fpg_temp = (String)map.get("height");
                if (!NumberUtil.isNumeric(fpg_temp)) {
                    throw new IllegalArgumentException("用户身高(height)为非法类型");
                }

                height = Double.valueOf(fpg_temp);
            }

            if (map.get("weight") != null) {
                if (!(map.get("weight") instanceof String)) {
                    throw new IllegalArgumentException("用户体重(weight)非字符串类型");
                }

                fpg_temp = (String)map.get("weight");
                if (!NumberUtil.isNumeric(fpg_temp)) {
                    throw new IllegalArgumentException("用户体重(weight)为非法类型");
                }

                weight = Double.valueOf(fpg_temp);
            }

            if (map.get("diabetes") != null) {
                if (!(map.get("diabetes") instanceof String)) {
                    throw new IllegalArgumentException("用户糖尿病类型(diabetes)非字符串类型");
                }

                fpg_temp = (String)map.get("diabetes");
                if (!NumberUtil.isDiabetes(fpg_temp)) {
                    throw new IllegalArgumentException("用户糖尿病类型(diabetes)为非法类型");
                }

                diabetes = Integer.valueOf(fpg_temp);
            }

            if (map.get("fpg") != null) {
                if (!(map.get("fpg") instanceof String)) {
                    throw new IllegalArgumentException("用户空腹血糖(fpg)非字符串类型");
                }

                fpg_temp = (String)map.get("fpg");
                if (!NumberUtil.isDoubleOrFloat(fpg_temp)) {
                    throw new IllegalArgumentException("用户空腹血糖(fpg)为非法类型");
                }

                fpg = Double.valueOf(fpg_temp);
                if (fpg < 3.0 || fpg > 20.9) {
                    throw new IllegalArgumentException("用户空腹血糖(fpg)超出正常范围(3.0-20.9)");
                }
            }

            if (map.get("medication") != null) {
                if (!(map.get("medication") instanceof ArrayList)) {
                    throw new IllegalArgumentException("用户用药情况(medication)非List类型");
                }

                ArrayList<Drug> drugs = (ArrayList)map.get("medication");
                medicationjs = this.getMedicationjs(drugs);
            }

            UpdateUserInfoParam body = new UpdateUserInfoParam();
            body.setId(userId);
            body.setUserGender(gender);
            body.setUserNickname(userName);
            body.setUserHeight(height);
            body.setUserWeight(weight);
            body.setUserDiagnoseType(diabetes);
            body.setUserUsedDurg(medicationjs);
            body.setUserFpg(fpg);
            if (birthday != null) {
                body.setUserBirthday(NumberUtil.dateToTimestamp(birthday));
            }

            body.setUserSyncVec(1);
            if (this.netUtil != null) {
                this.netUtil.updateUserInfo(body, this.callbackUpdateUserInfo);
            }

        }
    }

    private void netGetUserID(UserInfo userInfo) {
        UserInfoParam userInfoParam = new UserInfoParam();
        userInfoParam.setUserName(userInfo.getUserName());
        Double height = userInfo.getHeight() == null ? null : (double)userInfo.getHeight();
        userInfoParam.setUserHeight(height);
        Double weight = userInfo.getWeight() == null ? null : (double)userInfo.getWeight();
        userInfoParam.setUserWeight(weight);
        userInfoParam.setUserDiagnoseType(userInfo.getDiabetes());
        userInfoParam.setUserUsedDurg(userInfo.getMedicationjs());
        userInfoParam.setUserFpg(userInfo.getFpg());
        userInfoParam.setAppVersion(BuildConfigUtil.getVersionCode());
        if (this.netUtil != null) {
            this.netUtil.createUser(userInfoParam, this.callbackcreateUser);
        }

    }

    private void netUpdate(OriginalDataBean originalDataBean) {
        if (originalDataBean != null) {
            Metric metric = new Metric();
            if (NumberUtil.isNumeric(originalDataBean.getUserID())) {
                Double userID = Double.valueOf(originalDataBean.getUserID());
                metric.setUserId((long)userID.intValue());
            } else {
                metric.setUserId(123456L);
            }

            SimpleDateFormat ft = new SimpleDateFormat("yyyy-MM-dd HH-mm");
            Date date = null;

            try {
                date = ft.parse(originalDataBean.getMeasureTime());
            } catch (ParseException var11) {
                var11.printStackTrace();
            }

            long dd = date.getTime();
            metric.setTime(dd);
            metric.setValGlu(Double.valueOf(originalDataBean.getGLU()));
            metric.setValBv(Double.valueOf(originalDataBean.getSPD()));
            metric.setValPulse(Double.valueOf(originalDataBean.getPSE()));
            metric.setValSoa2(Double.valueOf(originalDataBean.getSOA()));
            metric.setValEt(Double.valueOf(originalDataBean.getET()));
            metric.setValEh(Double.valueOf(originalDataBean.getEH()));
            metric.setValAfterCorrected(Double.valueOf(originalDataBean.getCheckGlu()));
            metric.setMetricType(Integer.valueOf(originalDataBean.getMeal()));
            metric.setEatType(Integer.valueOf(this.userInfo.getEatType()));
            metric.setHeight(Double.valueOf(originalDataBean.getHeight()));
            metric.setWeight(Double.valueOf(originalDataBean.getWeight()));
            metric.setFpg(Double.valueOf(originalDataBean.getFpg()));
            metric.setDiabetes(Integer.valueOf(originalDataBean.getDiabetes()));
            metric.setMedicine(originalDataBean.getMedication());
            Gson gson = new Gson();
            String jsonMetric = gson.toJson(metric);
            UserTestResultParam userTestResultParam = new UserTestResultParam();
            userTestResultParam.setUserId(metric.getUserId());
            userTestResultParam.setMealTime(Long.valueOf(this.userInfo.getMealtime()));
            userTestResultParam.setDeviceSn(originalDataBean.getDeviceID());
            userTestResultParam.setRawData(new String(originalDataBean.getOriginalData()));
            userTestResultParam.setTest_data(jsonMetric);
            userTestResultParam.setAppVersion(BuildConfigUtil.getVersionCode());
            if (this.netUtil != null) {
                this.netUtil.UpdateData(userTestResultParam, this.callbackUpdateData);
            }

        }
    }

    public void setFingerGlu(Double fingerGlu) {
        this.fingerGlu = fingerGlu;
        if (this.netstate != null && this.netUtil != null && this.updataId != null && fingerGlu != null) {
            this.netUtil.UpdateFingerGluData(this.updataId.intValue(), this.fingerGlu, this.updateFingerGluCallback);
        }

    }

    private AbstractWorker glumeterWorker(boolean debug) {
        GlumeterWorker worker = new GlumeterWorker(this.listener, this.context);
        worker.setDebug(debug);
        return worker;
    }

    private AbstractWorker selfTestWorker(boolean debug) {
        SelfTestWorker worker = new SelfTestWorker(this.listener, this.context);
        worker.setDebug(debug);
        return worker;
    }

    private void checkUpdate() {
        if (!TextUtils.isEmpty(this.netstate)) {
            String ghaDeviceType = this.mCMD01Bean.getGhaDeviceType();
            if ("A03".equals(ghaDeviceType)) {
                this.netUtil.A03MCURegister(this.mCMD01Bean.getDeviceID(), this.MCURegistercallback);
                this.netUtil.A03BluetoothRegister(this.mCMD01Bean.getDeviceID(), this.BluetoothRegistercallback);
            } else if ("B03".equals(ghaDeviceType)) {
                this.netUtil.B03MCURegister(this.mCMD01Bean.getDeviceID(), this.MCURegistercallback);
                this.netUtil.B03BluetoothRegister(this.mCMD01Bean.getDeviceID(), this.BluetoothRegistercallback);
            }

            this.netUtil.PicRegister(this.mCMD01Bean.getDeviceID(), this.PicRegistercallback);
        }

    }

    private void updateReal() {
        this.log("提示需要升级,并检查升级类型进行升级");
        if (!updateRuning) {
            updateRuning = true;
            this.W_fireGlumeterEvent(new GlumeterEvent(GlumeterEventType.PRC_CANUPDATE, (Object)null));
        }

    }

    private int checkUpdateType() {
        if (this.MCUUpdateFilePaht != null && (new File(this.MCUUpdateFilePaht)).exists()) {
            return 1;
        } else if (this.BluetoothUpdateFilePaht != null && (new File(this.BluetoothUpdateFilePaht)).exists()) {
            return 2;
        } else {
            return this.PicUpdateFilePaht != null && (new File(this.PicUpdateFilePaht)).exists() ? 3 : 0;
        }
    }

    public void update() {
        if (measureRuning) {
            this.log("正在检测中，请勿升级");
            this.W_fireGlumeterEvent(new GlumeterEvent(GlumeterEventType.PRC_TESTING, (Object)null));
        } else {
            int tt = this.checkUpdateType();
            if (tt != 0) {
                this.update1(tt);
            }

        }
    }

    private void update1(int i) {
        if (i == 0) {
            updateType = 0;
        } else {
            CheckResponseResult.VersionBean versionBean;
            if (i == 1) {
                versionBean = (CheckResponseResult.VersionBean)this.mapMCUcheck.get("versionBean");
                updateType = 1;
                this.worker.update_start("1", this.authentication, new File(this.MCUUpdateFilePaht), versionBean.getMd5sum());
            } else if (i == 3) {
                versionBean = (CheckResponseResult.VersionBean)this.mapPiccheck.get("versionBean");
                updateType = 3;
                this.worker.update_start("2", (String)null, new File(this.PicUpdateFilePaht), versionBean.getMd5sum());
            } else if (i == 2) {
                updateType = 2;
                this.total_bluetoothUpdateWorker = new Total_BluetoothUpdateWorker(this.listener, this.context);
                this.total_bluetoothUpdateWorker.setDebug(this.debug);
                if ("A03".equals(this.mCMD01Bean.getGhaDeviceType())) {
                    this.total_bluetoothUpdateWorker.update_A03(AbstractWorker.mBleRssiDevice, this.BluetoothUpdateFilePaht);
                } else if ("B03".equals(this.mCMD01Bean.getGhaDeviceType())) {
                    this.total_bluetoothUpdateWorker.update_B03(AbstractWorker.mBleRssiDevice, this.BluetoothUpdateFilePaht);
                }
            }

        }
    }

    public void initN_GlumeterWorker(int type) {
        this.type = type;
        if (type == 1) {
            this.worker = this.glumeterWorker(this.debug);
        } else if (type == 2) {
            this.worker = this.selfTestWorker(this.debug);
        }

    }

    public void scan() {
        if (this.worker != null) {
            this.worker.scanConn();
        }

    }

    public void stopScan() {
        if (this.worker != null) {
            this.worker.stopScan();
        }

    }

    public void connDevice(BleRssiDevice bleRssiDevice) {
        if (this.worker != null) {
            this.worker.conn(bleRssiDevice);
        }

    }

    public void start() {
        if (this.worker != null) {
            if (this.type == 1) {
                if (this.userInfo != null) {
                    Map map = this.getMap();
                    if (map == null || map.size() == 0) {
                        return;
                    }

                    try {
                        this.worker.configure(map);
                    } catch (Exception var3) {
                        var3.printStackTrace();
                    }
                } else {
                    this.log("用户信息为空，没有获取到用户信息");
                }
            }

            this.worker.start();
            measureRuning = true;
        }

    }

    public void stop() {
        if (this.worker != null) {
            this.worker.stop();
        }

    }

    public void disConn() {
        if (this.worker != null) {
            this.worker.disConnect();
        }

    }

    private Map getMap() {
        Map<String, Object> map = new HashMap();
        if (this.userInfo == null) {
            this.log("没有用户信息");
            return null;
        } else {
            map.put("userId", this.userInfo.getUserId());
            map.put("userName", this.userInfo.getUserName());
            map.put("age", this.userInfo.getAge());
            map.put("height", this.userInfo.getHeight());
            map.put("weight", this.userInfo.getWeight());
            map.put("diabetes", String.valueOf(this.userInfo.getDiabetes()));
            map.put("fpg", this.userInfo.getFpg());
            map.put("meal", this.userInfo.getMeal());
            map.put("medication", this.userInfo.getMedication());
            map.put("mealtime", this.userInfo.getMealtime());
            map.put("checks", this.userInfo.getChecksNet());
            return map;
        }
    }

    public boolean isDebug() {
        return this.debug;
    }

    public void setDebug(boolean debug) {
        this.debug = debug;
    }

    private void W_fireGlumeterEvent(GlumeterEvent event) {
        if (this.w_glumeterListener != null) {
            this.w_glumeterListener.onEvent(event);
        }

    }

    private void W_fireGlumeterEvent(W_GlumeterEvent event) {
        if (this.w_glumeterListener != null) {
            this.w_glumeterListener.onEvent(event);
        }

    }

    private void log(String s) {
        if (this.debug) {
            Log.e("W_S_GlumeterWorker", s);
        }

    }

    private String getMedication(ArrayList<Drug> drugs) {
        if (drugs != null && drugs.size() != 0) {
            String huangniao = "0";
            String shuanggua = "0";
            String yizhiji = "0";
            String yidaoshu = "0";
            String noDrug = "1";
            String drugTypes = this.checkDrug(drugs, 1);
            if (drugTypes.contains("1")) {
                huangniao = "1";
                noDrug = "0";
            }

            if (drugTypes.contains("2")) {
                shuanggua = "1";
                noDrug = "0";
            }

            if (drugTypes.contains("3")) {
                yizhiji = "1";
                noDrug = "0";
            }

            if (drugTypes.contains("4")) {
                yidaoshu = "1";
                noDrug = "0";
            }

            return huangniao + shuanggua + yizhiji + yidaoshu + noDrug;
        } else {
            return "00001";
        }
    }

    private String getMedicationjs(ArrayList<Drug> drugs) {
        return drugs != null && drugs.size() != 0 ? this.checkDrug(drugs, 2) : null;
    }

    private String checkDrug(ArrayList<Drug> drugs, int type) {
        if (type != 1 && type != 2) {
            return null;
        } else {
            StringBuilder drugIds = new StringBuilder();
            drugIds.append("[");
            StringBuilder drugTypes = new StringBuilder();
            Drug drug = null;

            for(int i = 0; i < drugs.size(); ++i) {
                drug = (Drug)drugs.get(i);
                if (i == drugs.size() - 1) {
                    drugIds.append(drug.getId());
                } else {
                    drugIds.append(drug.getId() + ",");
                }

                drugTypes.append(drug.getDrugType());
            }

            drugIds.append("]");
            if (type == 1) {
                return drugTypes.toString();
            } else {
                return drugIds.toString();
            }
        }
    }
}
